/*
 * Copyright (c) 2007-2020 西安交通信息投资营运有限公司 版权所有
 */

package com.xci.edu.module.background.controller;

import com.github.lvyanyang.annotation.Authorize;
import com.github.lvyanyang.core.BaseWebController;
import com.github.lvyanyang.core.BoolResult;
import com.github.lvyanyang.core.Const;
import com.github.lvyanyang.core.XCI;
import com.xci.edu.core.entity.EduCoursewareDetails;
import com.xci.edu.core.filter.EduCoursewareDetailsFilter;
import com.xci.edu.core.service.EduCoursewareDetailsService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 课程明细页面控制器
 * @author 焦元义 jiaoyuanyi@xci96716.com
 * @since 2020-11-24 15:14:37
 */
@Authorize
@Controller
@RequestMapping(value = "/background/eduCoursewareDetails")
public class EduCoursewareDetailsController extends BaseWebController {
    /** 课程明细服务 */
    @Resource private EduCoursewareDetailsService eduCoursewareDetailsService;

    //region 页面

    /** 首页 */
    @GetMapping
//    @Authorize(code = "background.eduCoursewareDetails")
    public String index() {
        return "background/eduCoursewareDetails/index";
    }

    /** 新建页 */
    @GetMapping("/create")
    @Authorize(code = "background.eduCoursewareDetails.insert")
    public String create(String roleIds,ModelMap map) {
        createMark(map);
        var entity = new EduCoursewareDetails();
        entity.setId(XCI.nextId());
        // entity.setCoursewareId();
        // entity.setName();
        // entity.setUrl();
        // entity.setPath();
        map.put("entity", entity);
        return "background/eduCoursewareDetails/edit";
    }

    /** 编辑页 */
    @GetMapping("/edit")
    @Authorize(code = "background.eduCoursewareDetails.update")
    public String edit(String id, ModelMap map) {
        var entity = eduCoursewareDetailsService.selectById(Long.valueOf(id));
        XCI.checkNotFoundData(entity, id);
        map.put("entity", entity);
        return "background/eduCoursewareDetails/edit";
    }

    /** 详情页 */
    @GetMapping("/details")
    public String details(String id, ModelMap map) {
        var entity = eduCoursewareDetailsService.selectById(Long.valueOf(id));
        XCI.checkNotFoundData(entity, id);
        map.put("entity", entity);
        return "background/eduCoursewareDetails/details";
    }

    //endregion

    //region 处理

    /** 表格查询 */
    @ResponseBody
    @PostMapping("/grid")
    @Authorize(code = "background.eduCoursewareDetails.select")
    public BoolResult grid(EduCoursewareDetailsFilter filter) {
        return BoolResult.success(eduCoursewareDetailsService.selectPageList(filter));
    }

    /** 新建保存 */
    @ResponseBody
    @PostMapping("/createSave")
    //@Authorize(code = "background.eduCoursewareDetails.insert")
    public BoolResult createSave(@ModelAttribute EduCoursewareDetails entity) {
        return eduCoursewareDetailsService.insert(entity);
    }

    /** 修改保存 */
    @ResponseBody
    @PostMapping("/updateSave")
    //@Authorize(code = "background.eduCoursewareDetails.update")
    public BoolResult updateSave(@ModelAttribute EduCoursewareDetails entity) {
        return eduCoursewareDetailsService.update(entity);
    }

    /** 删除 */
    @ResponseBody
    @PostMapping("/delete")
    //@Authorize(code = "background.eduCoursewareDetails.delete")
    public BoolResult delete(String ids) {
        return eduCoursewareDetailsService.delete(ids);
    }

    /** 修改状态 */
    @ResponseBody
    @PostMapping("/status")
    @Authorize(code = "background.eduCoursewareDetails.updateStatus")
    public BoolResult status(String id, Integer status) {
        eduCoursewareDetailsService.updateStatus(id, XCI.toBool(status));
        return BoolResult.success();
    }

    /** 导出 */
    @GetMapping("/export")
    //@Authorize(code = "background.eduCoursewareDetails.export")
    public void export(EduCoursewareDetailsFilter filter) {
        XCI.exportExcel(eduCoursewareDetailsService.selectList(filter), EduCoursewareDetails.class, "课程明细列表");
    }

    //endregion
}
